package me.tuyou.jvm.oom;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

/**
 * 直接内存分配报错演示
 * 报错：java.lang.OutOfMemoryError: Java heap space
 */
//-Xms1000M -Xmx1000M -XX:MaxDirectMemorySize=5M -Xss128m -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=~/work/heapDumpExceeded.hprof
public class DirectMemoryOutOfMemory {
	public static void main(String[] args) {
		List<ByteBuffer> list = new ArrayList<ByteBuffer>();
		while(true){
			ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
//			ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024);
			list.add(buffer);
		}
	}
}
